<template>
  <div class="content">
    <t-dialog
        v-model:visible="visible"
        width="431"
        placement="center"
        :on-close="onClose"
        :cancel-btn="null"
        :confirm-btn="null"
    >
      <template #header>
        <div class="headerBox">
          <svg-icon
              :name="'icon-infoIcon'"
              class-name="infoIcon-svg-icon"
          ></svg-icon>
          <span class="titleText">确认重新质检</span>
        </div>
      </template>
      <template #body>
        <div class="infoBox">
          共重新质检<span class="underBox">{{ props.qualityIdList.length }}条</span>，重新质检发起后，原质检数据将被<span class="underBox">清空</span>
        </div>
        <div>
          <div class="separateBox">重新话者分离</div>
          <t-radio-group v-model="separate">
            <t-radio :value="1">是</t-radio>
            <t-radio :value="0">否</t-radio>
          </t-radio-group>
        </div>
      </template>
      <template #footer>
        <t-button @click="handleCancel" class="cancelBtn" variant="text">取消</t-button>
        <t-button @click="handleConfirm" class="confirmBtn">确认</t-button>
      </template>
    </t-dialog>

  </div>
</template>

<script setup>
import {ref, watch} from 'vue';
import {resultReload} from "../../../api/qualityResult";
import { MessagePlugin } from 'tdesign-vue-next';

const props = defineProps({
  resetVisible: Boolean,
  closeResetDialog: Function,
  qualityIdList: Array,
})
const emits = defineEmits()
const visible = ref(false);
watch(() => props.resetVisible, (newVal, oldVal) => {
  visible.value = newVal
})

const separate = ref(0)

// 确定
const handleConfirm = () => {
  let data = {
    type: separate.value,
    ids: props.qualityIdList
  }
  resultReload(data).then(res => {
    console.log('重新质检', res)
    if(res.code === 0) {
      MessagePlugin.success('已重新质检！')
      separate.value = 0
      emits('closeResetDialog', true)
    }
  }).catch(error => {
    console.log(error)
    emits('closeResetDialog')
  })
}
// 取消
const handleCancel = () => {
  separate.value = 0
  emits('closeResetDialog')
}
const onClose = () => {
  separate.value = 0
  emits('closeResetDialog')
};
</script>

<style lang="scss" scoped>
:deep(.t-dialog) {
  padding: 24px 22px 18px 22px;
}
:deep(.t-dialog__header) {
  .headerBox {
    display: flex;
    .infoIcon-svg-icon {
      height: 24px;
      width: 24px;
      margin-right: auto;
    }
    .titleText {
      margin-left: 10px;
      font-size: 16px;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.9);
    }
  }

}
:deep(.t-dialog__body) {
  .infoBox {
    width: 100%;
    height: 38px;
    line-height: 38px;
    font-size: 13px;
    font-weight: 400;
    border-radius: 6px;
    background: rgba(245, 246, 247, 1);
    color: rgba(89, 89, 89, 1);
    padding-left: 11px;
    margin-bottom: 16px;
    .underBox {
      text-decoration-line: underline;
      color: rgba(227, 77, 89, 1);
    }
  }
}
.separateBox {
  font-size: 13px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  padding-bottom: 8px;
}
:deep(.t-radio-group) {
  .t-radio__label {
    font-size: 12px;
    font-weight: 400;
    color: rgba(92, 91, 91, 1);
  }
}
.cancelBtn {
  height: 28px;
  width: 60px;
  background: rgba(255, 255, 255, 1);
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
}
.cancelBtn {
  background: rgba(255, 255, 255, 1);
}
.confirmBtn {
  height: 28px;
  width: 60px;
  background: rgba(30, 117, 254, 1);
  font-size: 14px;
  font-weight: 400;
  color: rgba(255, 255, 255, 1);
}
</style>
